package com.uwlaser.service.impl;

import com.uwlaser.base.impl.CommonServiceImpl;
import com.uwlaser.domain.AntonConfig;
import com.uwlaser.domain.AntonConfigDevice;
import com.uwlaser.service.AntonConfigDeviceService;
import com.uwlaser.service.mapper.AntonConfigDeviceMapper;
import com.uwlaser.service.mapper.AntonConfigMapper;
import com.uwlaser.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;

/**
 * @author yangwei
 * @create 2022/12/2
 */
@Service
@AllArgsConstructor
// @CacheConfig(cacheNames = FactoryModelService.CACHE_KEY)
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class AntonConfigDeviceServiceImpl  extends CommonServiceImpl<AntonConfigDeviceMapper, AntonConfigDevice> implements AntonConfigDeviceService {
    @Autowired
    private AntonConfigDeviceMapper antonConfigDeviceMapper ;

    @Override
    public int insert(AntonConfigDevice resources) {
        if(StringUtils.isEmpty(resources.getAntonCode()) || StringUtils.isEmpty(resources.getDeviceCode())){
            throw new RuntimeException("安东编码或设备编码不能为空！");
        }
        return antonConfigDeviceMapper.insert(resources);
    }

    @Override
    public boolean updateById(AntonConfigDevice resources) {
        return false;
    }

    @Override
    public int removeById(Integer id) {
        if(id==null){
            throw new RuntimeException("安东配置与设备关联表id不能为空！");
        }
        return antonConfigDeviceMapper.deleteById(id);
    }

    @Override
    public int removeByIds(Set<Integer> ids) {
        if(ids==null || ids.size()<1){
            throw new RuntimeException("安东配置与设备关联表id不能为空！");
        }
        return antonConfigDeviceMapper.deleteBatchIds(ids);
    }
}
